package com.hmall.common.utils;

import lombok.extern.slf4j.Slf4j;

/**
 * @author ljc
 * @version V1.0
 * @date 2025-03-20 21:28
 */
@Slf4j
public class UserContext {
    private static final ThreadLocal<Long> TL = new ThreadLocal<>();

    public static void setUser(Long userId) {
        log.info("设置用户id:{},线程名：{}", userId, Thread.currentThread().getName());
        TL.set(userId);

    }
    public static Long getUser() {
        log.info("设置用户id:{},线程名：{}", TL.get(), Thread.currentThread().getName());
        return TL.get();
    }
    public static void removeUser() {
        TL.remove();
    }

}
